﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="EditProfile.ascx.cs" Inherits="SonCa.SocialNetwork.Web.Accounts.ASCX.EditProfile" %>

<script type="text/javascript">
    $(document).ready(function () {                
//        $("#accordion").accordion({
//            heightStyle: "fill"
//        });        
    });    

    function changeContent(index) {
        $("#accordion").accordion({ heightStyle: "fill", active: index });
    }    
    
    function DisplayMessage_ep(element, error) {
        $(element).show('slow');
        $(element).text(error).delay(2000);
        $(element).hide('slow');
    }

    // Profile Info
    function SaveProfileInfo() {
        $("#error_profileInfo").css("color", "red");
        var name_ep = $("#<%=txtFullName.ClientID%>").val();        
        if (name_ep.length == 0) {
            DisplayMessage_ep("#error_profileInfo", "Xin nhập họ tên.");
            $("#<%=txtFullName.ClientID%>").focus();
            return false;
        }
        var birth_ep = $("#<%=txtBirthDate.ClientID%>").val();
        if (birth_ep.length == 0) {
            DisplayMessage_ep("#error_profileInfo", "Xin chọn ngày sinh.");
            $("#<%=txtBirthDate.ClientID%>").focus();
            return false;
        }
        var email_ep = $("#<%=txtEmail.ClientID%>").val();
        if (email_ep.length == 0) {
            DisplayMessage_ep("#error_profileInfo", "Xin nhập email.");
            $("#<%=txtEmail.ClientID%>").focus();
            return false;
        }
        var rs = new RegExp("([A-Za-z0-9_.-]){2,}@([A-Za-z0-9_.-]){2,}.([A-Za-z0-9_.-]){2,}");
        if (email_ep.match(rs) == null) {
            DisplayMessage_ep("#error_profileInfo", "Email không hợp lệ.");
            $("#<%=txtEmail.ClientID%>").focus();
            return false;
        }
        var gioitinh_ep = $("#<%=ddlGender.ClientID%>").val();        
        var gioithieu_ep = $("#<%=txtAboutMe.ClientID%>").val();
        var sothich_ep = $("#<%=txtInterests.ClientID%>").val();
        $.ajax({
            type: "post",
            url: "../Services/AjaxService.svc/UpdateProfileInfo",
            data: '{"fullname": "' + name_ep + '","birthday": "' + birth_ep + '","gender": "' + gioitinh_ep + '","email": "' + email_ep + '","aboutme": "' + gioithieu_ep + '","interests": "' + sothich_ep + '"}',
            contentType: "application/json; charset=utf-8;",
            dataType: "json",
            beforeSend: function () {
                $("#loading_info_ep").show();
            },
            success: function (response) {
                if (response.d == "ok") {
                    $("#error_profileInfo").css("color", "green");
                    DisplayMessage_ep("#error_profileInfo", "Thay đổi thông tin thành công.");                    
                    $("#loading_info_ep").hide();

                    RefreshProfileInfo(name_ep, birth_ep);
                }
                else {
                    DisplayMessage_ep("#error_profileInfo", "Cập nhật thất bại,hãy kiểm tra thông tin.");
                    $("#loading_info_ep").hide();
                }
            }
        });
    }

    function ClearProfileInfo() {
        $("#<%=txtFullName.ClientID%>").val("");
        $("#<%=txtBirthDate.ClientID%>").val("");
        $("#<%=txtEmail.ClientID%>").val("");
        $("#<%=txtAboutMe.ClientID%>").val("");
        $("#<%=txtInterests.ClientID%>").val("");
    }

    // Education
    function SaveEducationInfo() {
        $("#error_education").css("color", "red");
        var schoolName = $("#<%=txtSchoolName.ClientID%>").val();
        if (schoolName.length == 0) {
            DisplayMessage_ep("#error_education", "Xin nhập tên trường.");
            $("#<%=txtSchoolName.ClientID%>").focus();
            return false;
        }
        var startYear = $("#<%=ddlStartYear.ClientID%>").val();
        var graduationYear = $("#<%=ddlGraduationYear.ClientID%>").val();
        if (Number(graduationYear) < Number(startYear)) {
            DisplayMessage_ep("#error_education", "Niên khóa chưa đúng.");
            return false;
        }
        var city = $("#<%=ddlSchoolCity.ClientID%>").val();
        var grade = $("#<%=ddlGrade.ClientID%>").val();
        $.ajax({
            type: "post",
            url: "../Services/AjaxService.svc/UpdateEducationInfo",
            data: '{"schoolname": "' + schoolName + '","city": "' + city + '","grade": "' + grade + '","startyear": "' + startYear + '","graduationyear": "' + graduationYear + '"}',
            contentType: "application/json; charset=utf-8;",
            dataType: "json",
            beforeSend: function () {
                $("#loading_education_ep").show();
            },
            success: function (response) {
                if (response.d != "") {
                    $("#error_education").css("color", "green");
                    DisplayMessage_ep("#error_education", "Thay đổi thông tin thành công.");
                    $("#loading_education_ep").hide();
                }
                else {
                    DisplayMessage_ep("#error_education", "Cập nhật thất bại, hãy kiểm tra lại thông tin và thử lại.");
                    $("#loading_education_ep").hide();
                }
            }
        });
    }

    function ClearEducationInfo() {
        $("#<%=txtSchoolName.ClientID%>").val("");
    }

    // WorkPlace
    function SaveWorkPlaceInfo() {
        $("#error_workplace").css("color", "red");
        var companyName = $("#<%=txtCompanyName.ClientID%>").val();
        if (companyName.length == 0) {
            DisplayMessage_ep("#error_workplace", "Xin nhập tên công ty");
            $("#<%=txtCompanyName.ClientID%>").focus();
            return false;
        }
        var companyAddress = $("#<%=txtCompanyAddress.ClientID%>").val();
        if (companyAddress.length == 0) {
            DisplayMessage_ep("#error_workplace", "Xin nhập địa chỉ công ty");
            $("#<%=txtCompanyAddress.ClientID%>").focus();
            return false;
        }
        var position = $("#<%=txtPosition.ClientID%>").val();
        if (position.length == 0) {
            DisplayMessage_ep("#error_workplace", "Xin nhập chức vụ");
            $("#<%=txtPosition.ClientID%>").focus();
            return false;
        }
        var startDate = $("#<%=txtStartDate.ClientID%>").val();        
        var endDate = $("#<%=txtEndDate.ClientID%>").val();
        if (startDate.length == 0 || endDate.length == 0) {
            DisplayMessage_ep("#error_workplace", "Xin chọn thời gian.");            
            return false;
        }
        var checkstartDate = new Date(startDate);        
        var checkendDate = new Date(endDate);
        if (checkendDate.getTime() < checkstartDate.getTime()) {
            DisplayMessage_ep("#error_workplace", "Thời gian chưa đúng.");
            return false;
        }        
        var city = $("#<%=ddlCompanyCity.ClientID%>").val();
        var jobField = $("#<%=ddlJobField.ClientID%>").val();                
        $.ajax({
            type: "post",
            url: "../Services/AjaxService.svc/UpdateWorkPlaceInfo",
            data: '{"companyName": "' + companyName + '","companyAddress": "' + companyAddress + '","city": "' + city + '","jobField": "' + jobField + '","position": "' + position + '","startDate": "' + startDate + '","endDate": "' + endDate + '"}',
            contentType: "application/json; charset=utf-8;",
            dataType: "json",
            beforeSend: function () {
                $("#loading_workplace_ep").show();
            },
            success: function (response) {
                if (response.d != "") {
                    $("#error_workplace").css("color", "green");
                    DisplayMessage_ep("#error_workplace", "Thay đổi thông tin thành công.");
                    $("#loading_workplace_ep").hide();
                }
                else {
                    DisplayMessage_ep("#error_workplace", "Cập nhật thất bại, hãy kiểm tra lại thông tin và thử lại.");
                    $("#loading_workplace_ep").hide();
                }
            }
        });
    }    

    function ClearWorkPlaceInfo() {
        $("#<%=txtCompanyName.ClientID%>").val("");
        $("#<%=txtCompanyAddress.ClientID%>").val("");
        $("#<%=txtPosition.ClientID%>").val("");
        $("#<%=txtStartDate.ClientID%>").val("");
        $("#<%=txtEndDate.ClientID%>").val("");
    }

    // Location
    function SaveLocationInfo() {
        $("#error_location").css("color", "red");
        var locationName = $("#<%=txtLocationName.ClientID%>").val();
        if (locationName.length == 0) {
            DisplayMessage_ep("#error_location", "Xin nhập quận,huyện.");
            $("#<%=txtLocationName.ClientID%>").focus();
            return false;
        }
        var locationAddress = $("#<%=txtLocationAddress.ClientID%>").val();
        if (locationAddress.length == 0) {
            DisplayMessage_ep("#error_location", "Xin nhập địa chỉ.");
            $("#<%=txtLocationAddress.ClientID%>").focus();
            return false;
        }
        var startDate = $("#<%=txtLocationStartDate.ClientID%>").val();
        var endDate = $("#<%=txtLocationEndDate.ClientID%>").val();
        if (startDate.length == 0 || endDate.length == 0) {
            DisplayMessage_ep("#error_location", "Xin nhập thời gian sống.");            
            return false;
        }
        var checkStart = new Date(startDate);
        var checkEnd = new Date(endDate);
        if (checkEnd.getTime() < checkStart.getTime()) {
            DisplayMessage_ep("#error_location", "Thời gian chưa đúng.");
            return false;
        }
        var city = $("#<%=ddlLocationCity.ClientID%>").val();
        $.ajax({
            type: "post",
            url: "../Services/AjaxService.svc/UpdateLocationInfo",
            data: '{"locationName": "' + locationName + '","locationAddress": "' + locationAddress + '","city": "' + city + '","startDate": "' + startDate + '","endDate": "' + endDate + '"}',
            contentType: "application/json; charset=utf-8;",
            dataType: "json",
            beforeSend: function () {
                $("#loading_location_ep").show();
            },
            success: function (response) {
                if (response.d != "") {
                    $("#error_location").css("color", "green");
                    DisplayMessage_ep("#error_location", "Thay đổi thông tin thành công.");
                    $("#loading_location_ep").hide();
                }
                else {
                    DisplayMessage_ep("#error_location", "Cập nhật thất bại, hãy kiểm tra lại thông tin và thử lại.");
                    $("#loading_location_ep").hide();
                }
            }
        });
    }

    function ClearLocationInfo() {
        $("#<%=txtLocationName.ClientID%>").val("");
        $("#<%=txtLocationAddress.ClientID%>").val("");
        $("#<%=txtLocationStartDate.ClientID%>").val("");
        $("#<%=txtLocationEndDate.ClientID%>").val("");
    }
</script>

<h4 class="icon1">Thông tin cá nhân</h4>
<div id="accordion">
    <h3>
        Thông tin cơ bản
        <img src="../img/loading_24.gif" id="loading_info_ep" style="display:none" />
    </h3>
    <div id="error_profileInfo" style="color:Red;font-weight:bold;font-size:14px;display:none"></div>
    <div>
        <div class="pf_info">
            <div class="left">Họ tên</div>
            <div class="right">
                <input type="text" id="txtFullName" class="input_block_level" runat="server" />
            </div>
        </div>
        <div class="pf_info">
            <div class="left">Ngày sinh</div>
            <div class="right">
                <input type="text" id="txtBirthDate" class="input_block_level tcal" runat="server" />
            </div>
        </div>
        <div class="pf_info">
            <div class="left">Giới tính</div>
            <div class="right">
                <asp:DropDownList runat="server" ID="ddlGender">
                    <asp:ListItem Value="0" Text="Nam"></asp:ListItem>
                    <asp:ListItem Value="1" Text="Nữ"></asp:ListItem>
                </asp:DropDownList>
            </div>
        </div>
        <%--<div class="row">
            <div class="left">
                Quốc gia
            </div>
            <div class="right">
                <asp:DropDownList runat="server" ID="ddlNation">
                </asp:DropDownList>
            </div>
        </div>--%>
        <%--<div class="pf_info">
            <div class="left">Tỉnh, Thành</div>
            <div class="right">
                <asp:DropDownList runat="server" ID="ddlCity">
                </asp:DropDownList>
            </div>
        </div>--%>
        <div class="pf_info">
            <div class="left">Email</div>
            <div class="right">
                <input type="text" id="txtEmail" class="input_block_level" runat="server" />
            </div>
        </div>
        <div class="pf_info">
            <div class="left">Lời giới thiệu</div>
            <div class="right">
                <textarea id="txtAboutMe" runat="server" class="input_block_level"></textarea>
            </div>
        </div>
        <div class="pf_info">
            <div class="left">Sở thích</div>
            <div class="right">
                <textarea id="txtInterests" runat="server" class="input_block_level"></textarea>
            </div>
        </div>
        <div class="pf_info" style="margin: 10px;">
            <div class="left">&nbsp;</div>
            <div class="right" style="text-align: center;">
                <input type="button" id="btnSaveProfileInfo" class="button" value="Cập nhật" onclick="SaveProfileInfo()" />
                <input type="button" id="btnCancelProfileInfo" class="button" value="Làm lại" onclick="ClearProfileInfo()" />                
            </div>
        </div>
    </div>
    <h3>
        Học hành
        <img src="../img/loading_24.gif" id="loading_education_ep" style="display:none" />
    </h3>
    <div id="error_education" style="color:Red;font-weight:bold;font-size:14px;display:none"></div>
    <div>
        <%--<div class="pf_info">
            <div class="left">
                Quốc gia
            </div>
            <div class="right">
                <asp:DropDownList runat="server" ID="ddlSchoolNation">
                </asp:DropDownList>
            </div>
        </div>--%>
        <div class="pf_info">
            <div class="left">Tên trường</div>
            <div class="right">
                <input type="text" id="txtSchoolName" runat="server" class="input_block_level" />
            </div>
        </div>
        <%--<div class="pf_info">
            <div class="left">
                Địa chỉ
            </div>
            <div class="right">
                <asp:TextBox ID="txtSchoolAddress" runat="server" CssClass="input_block_level"></asp:TextBox></div>
        </div>--%>
        <div class="pf_info">
            <div class="left">Tỉnh, thành</div>
            <div class="right">
                <asp:DropDownList runat="server" ID="ddlSchoolCity">
                </asp:DropDownList>
            </div>
        </div>
        <div class="pf_info">
            <div class="left">Trình độ</div>
            <div class="right">
                <asp:DropDownList runat="server" ID="ddlGrade">
                </asp:DropDownList>
            </div>
        </div>
        <div class="pf_info">
            <div class="left">Niên khóa</div>
            <div class="right">
                <asp:DropDownList ID="ddlStartYear" runat="server" CssClass="year_select">
                </asp:DropDownList>
                <asp:DropDownList ID="ddlGraduationYear" runat="server" CssClass="year_select">
                </asp:DropDownList>
            </div>
        </div>
        <div class="pf_info" style="margin: 10px;">
            <div class="left">&nbsp;</div>
            <div class="right" style="text-align: center;">
                <input type="button" id="btnSaveEducation" class="button" value="Cập nhật" onclick="SaveEducationInfo()" />
                <input type="button" id="btnCancelEducation" class="button" value="Làm lại" onclick="ClearEducationInfo()" />                
            </div>
        </div>
    </div>
    <h3>
        Nghề nghiệp
        <img src="../img/loading_24.gif" id="loading_workplace_ep" style="display:none" />
    </h3>
    <div id="error_workplace" style="color:Red;font-weight:bold;font-size:14px;display:none"></div>
    <div>
        <div class="pf_info">
            <div class="left">Công ty</div>
            <div class="right">
                <input type="text" id="txtCompanyName" runat="server" class="input_block_level"/>
            </div>
        </div>
        <div class="pf_info">
            <div class="left">Địa chỉ</div>
            <div class="right">
                <input id="txtCompanyAddress" runat="server" class="input_block_level"/>
            </div>
        </div>
        <%--<div class="pf_info">
            <div class="left">
                Quốc gia
            </div>
            <div class="right">
                <asp:DropDownList runat="server" ID="ddlCompanyNation">
                </asp:DropDownList>
            </div>
        </div>--%>
        <div class="pf_info">
            <div class="left">Tỉnh, thành</div>
            <div class="right">
                <asp:DropDownList runat="server" ID="ddlCompanyCity">
                </asp:DropDownList>
            </div>
        </div>
        <div class="pf_info">
            <div class="left">Lĩnh vực</div>
            <div class="right">
                <asp:DropDownList runat="server" ID="ddlJobField">
                </asp:DropDownList>
            </div>
        </div>
        <div class="pf_info">
            <div class="left">Chức vụ</div>
            <div class="right">
                <input type="text" id="txtPosition" runat="server" class="input_block_level"/>
            </div>
        </div>
        <div class="pf_info">
            <div class="left">Thời gian</div>
            <div class="right">
                <input type="text" id="txtStartDate" runat="server" class="input_block_level year_select tcal"/>
                <input type="text" id="txtEndDate" runat="server" class="input_block_level year_select tcal"/>
            </div>
        </div>
        <div class="pf_info">
            <div class="left">&nbsp;</div>
            <div class="right" style="text-align: center;">
                <input type="button" id="btnSaveWorkPlace" class="button" value="Cập nhật" onclick="SaveWorkPlaceInfo()" />
                <input type="button" id="btnCancelWorkPlace" class="button" value="Làm lại" onclick="ClearWorkPlaceInfo()" />
            </div>
        </div>
    </div>
    <h3>
        Nơi ở
        <img src="../img/loading_24.gif" id="loading_location_ep" style="display:none" />
    </h3>
    <div id="error_location" style="color:Red;font-weight:bold;font-size:14px;display:none"></div>
    <div>
        <div class="pf_info">
            <div class="left">Quận,huyện</div>
            <div class="right">
                <input type="text" id="txtLocationName" runat="server" class="input_block_level"/>
            </div>
        </div>
        <div class="pf_info">
            <div class="left">Địa chỉ</div>
            <div class="right">
                <input type="text" id="txtLocationAddress" runat="server" class="input_block_level"/>
            </div>
        </div>
        <%--<div class="pf_info">
            <div class="left">
                Quốc gia
            </div>
            <div class="right">
                <asp:DropDownList runat="server" ID="ddlLocationNation">
                </asp:DropDownList>
            </div>
        </div>--%>
        <div class="pf_info">
            <div class="left">Tỉnh, thành</div>
            <div class="right">
                <asp:DropDownList runat="server" ID="ddlLocationCity">
                </asp:DropDownList>
            </div>
        </div>
        <div class="pf_info">
            <div class="left">Thời gian sống</div>
            <div class="right">
                <input type="text" id="txtLocationStartDate" runat="server" class="input_block_level year_select tcal"/>
                <input type="text" id="txtLocationEndDate" runat="server" class="input_block_level year_select tcal"/>
            </div>
        </div>
        <div class="pf_info">
            <div class="left">&nbsp;</div>
            <div class="right" style="text-align: center;">
                <input type="button" id="btnSaveLocation" class="button" value="Cập nhật" onclick="SaveLocationInfo()" />
                <input type="button" id="btnCancelLocation" class="button" value="Làm lại" onclick="ClearLocationInfo()" />                
            </div>
        </div>
    </div>
</div>
